<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('角色列表')" />
</head>
<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="role-form">
					<div class="select-list">
						<ul>
							<li>
								仓库名称：<input type="text" name="wareName"/>
							</li>
							<li>
								所属区域：
								<select id="pr">
									<option value="0">请选择</option>
									<option th:each="pr:${prs}" th:value="${pr.provId}" th:text="${pr.provName}"></option>
								</select>
								<select id="city" name="sysCityId">
								</select>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
		
			<div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-success" onclick="$.operate.add()">
	                <i class="fa fa-plus"></i> 新增
	            </a>
	        </div>
	        
	        <div class="col-sm-12 select-table table-striped">
			    <table id="bootstrap-table"></table>
			</div>

		</div>
	</div>
	<th:block th:include="include :: footer" />
	<script th:inline="javascript">
		var editFlag = [[${@permission.hasPermi('storage:ware:edit')}]];
		var removeFlag = [[${@permission.hasPermi('storage:ware:remove')}]];
		var prefix = ctx + "storage/ware";
		

		$(function() {
		    var options = {
		        url: prefix + "/list",
		        createUrl: prefix + "/add",
				detailUrl: prefix + "/details/{id}",
		        updateUrl: prefix + "/edit/{id}",
		        removeUrl: prefix + "/remove",
		        modalName: "仓库",
		        columns: [{
		            checkbox: true
		        },
				{
					title: '编号',
					formatter:function(value,row,index) {
						return $.table.serialNumber((index));
					}
				},
		        {
		            field: 'wareId',
		            title: '编号',
					visible:false
		        },
		        {
		            field: 'wareName',
		            title: '仓库名称',
		        },
		        {
		            field: 'sysChargeUser',
		            title: '负责人',
		        },
				{
					field: 'cityName',
					title: '所属区域',
				},
				{
					field: 'repoStatus',
					title: '状态',
					formatter: function (value) {
						if (value == 0) {
							return '不可用'
						}else {
							return '可用'
						}
					}
				},
				{
					field: 'createTime',
					title: '创建时间',
				},
				{
					field: 'createName',
					title: '创建人',
				},
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
		            	if (row.wareId != 0) {
							var action = [];
							action.push('<a class="btn btn-success btn-sm" style="margin-right: 5px" onclick="$.operate.detail('+ row.wareId +')">查看详情</a>');
							if (row.repoStatus == 0) {
								action.push('<a class="btn btn-primary btn-sm" href="#" onclick="isAble(1,'+ row.wareId +')">恢复</a>');
							}else {
								action.push('<a class="btn btn-warning btn-sm" href="#" style="margin-right: 5px;" onclick="$.operate.edit('+ row.wareId +')">修改</a>');
								action.push('<a class="btn btn-danger btn-sm" href="#" onclick="isAble(0,'+ row.wareId +')">撤销</a>')
							}
		                    return action.join('');
		            	} else {
		                    return "";
		                }
		            }
		        }]
		    };
		    $.table.init(options);
		});

		function isAble(op,id) {
			$.ajax({
				cache : true,
				type : "POST",
				url : ctx + "storage/ware/editStatus",
				data : {
					"wareId": id,
					"repoStatus": op
				},
				async : false,
				error : function(request) {
					$.modal.alertError("系统错误");
				},
				success : function(data) {
					$.operate.successCallback(data);
				}
			});
		}

		$("#pr").change(function () {
			$.get("/storage/ware/city/" + $("#pr").val(),{},function (data) {
				let options = '';
				for (let i = 0; i < data.length; i++) {
					options += '<option value="'+ data[i].cityId +'">'+ data[i].cityName +'</option>'
				}

				$("#city").html(options);
			})
		})
	</script>
</body>
</html>